import request from '@/assets/js/request';
import util from '@/assets/js/public';
import { getToken } from '@/assets/js/auth';

/// APPCode (待用)
const dwdyytCode = 'dwdyytxx';


/// 获取用户信息
export function getUserData(params) {
    console.log('获取用户信息时的名字是：' + params.userName);
    return request(
        {
            url: process.env.VUE_APP_URL + '/action/openapi/bps/common/transmit/getCurrentUser$sso',
            contentType: 'application/json;charset=UTF-8',
            data: {
                'access_token': getToken(),
                'appCode': dwdyytCode,
                'noAction': '1',
                'versionName': '2.7.92',
                'kv': {
                    'versionName': '2.7.92',
                    'versionCode': 2079200,
                    'appcode': dwdyytCode,
                    'currentUserCode': util.encrypt(params.userName),
                }
            }
        }
    )
}

/// 待办
export function getToDoList(params) {
    return request(
        {
            url: process.env.VUE_APP_URL + '/action/openapi/bps/common/transmit/' +
                'queryActBusinessStatus$api$myTaskToDo',
            contentType: 'application/json;charset=UTF-8',
            data: {
                'access_token': getToken(),
                'appCode': dwdyytCode,
                'currentUserCode': util.encrypt(params.userName),
                'versionName': '2.7.92',
                'kv': {
                    'currentUserCode': util.encrypt(params.userName),
                    'source': 'MOBILE',
                    'title': params.searchTitle,

                    'page': params.page,
                    'rows': params.rows,
                    'size': params.size,
                },
            }
        }
    )
}

/// 已办
export function getDoneList(params) {
    return request(
        {
            url: process.env.VUE_APP_URL + '/action/openapi/bps/common/transmit/' +
                'queryActBusinessStatus$api$queryMyJoin',
            contentType: 'application/json;charset=UTF-8',
            data: {
                'access_token': getToken(),
                'appCode': dwdyytCode,
                'currentUserCode': util.encrypt(params.userName),
                'versionName': '2.7.92',
                'kv': {
                    'currentUserCode': util.encrypt(params.userName),
                    'source': 'MOBILE',
                    'title': params.searchTitle,

                    'page': params.page,
                    'rows': params.rows,
                    'size': params.size,
                },
            }
        }
    )
}

/// 草稿箱
export function getDraftList(params) {
    return request(
        {
            url: process.env.VUE_APP_URL + '/action/openapi/bps/common/transmit/' +
                'queryActBusinessStatus$api$myDraftToDo',
            contentType: 'application/json;charset=UTF-8',
            data: {
                'access_token': getToken(),
                'appCode': dwdyytCode,
                'currentUserCode': util.encrypt(params.userName),
                'versionName': '2.7.92',
                'kv': {
                    'currentUserCode': util.encrypt(params.userName),
                    'source': 'MOBILE',
                    'title': params.searchTitle,

                    'page': params.page,
                    'rows': params.rows,
                    'size': params.size,
                },
            }
        }
    )
}



/// 第一议题 详情
export function getDYYTDetail(params) {
    return request(
        {
            url: process.env.VUE_APP_URL + '/action/openapi/bps/common/transmit/' +
                'UsStudy$api$getFormDetail',
            contentType: 'application/json;charset=UTF-8',
            data: {
                'access_token': getToken(),
                'appCode': dwdyytCode,
                'currentUserCode': util.encrypt(params.userName),
                'versionName': '2.7.92',
                'kv': {
                    'source': 'MOBILE',
                    'pmInsId': params.pmInsId,
                    'processInstId': params.processInstId,
                    'workFlag': params.workFlag,
                    'currentUserCode': util.encrypt(params.userName),
                },
            }
        }
    )
}


/// 第一议题 决策项
export function dyytGetDecisions(params) {
    console.log('name:' + params.userName)
    var usrls = 'UsStudy$api$getDecisions';
    return request(
        {
            url: process.env.VUE_APP_URL + '/action/openapi/bps/common/transmit/' + usrls + '?source=MOBILE',
            contentType: 'application/json;charset=UTF-8',
            data: {
                'access_token': getToken(),
                'appCode': dwdyytCode,
                'currentUserCode': util.encrypt(params.userName),
                'versionName': '2.7.92',
                'source': 'MOBILE',
                'kv': {
                    'currentUserCode': util.encrypt(params.userName),
                    'source': 'MOBILE',
                    'location': params.idcode.location,
                    'processInstId': params.idcode.processInstId,
                    'processDefName': params.idcode.processDefName,
                }
            }
        }
    )
}

/// 第一议题 决策项出人
export function dyytGetNextUser(params) {
    console.log('name:' + params.userName)
    var usrls = 'UsStudy$api$getOrgAndUser';
    return request(
        {
            url: process.env.VUE_APP_URL + '/action/openapi/bps/common/transmit/' + usrls + '?source=MOBILE',
            contentType: 'application/json;charset=UTF-8',
            data: {
                'access_token': getToken(),
                'appCode': dwdyytCode,
                'currentUserCode': util.encrypt(params.userName),
                'versionName': '2.7.92',
                'source': 'MOBILE',
                'kv': {
                    'currentUserCode': util.encrypt(params.userName),
                    'source': 'MOBILE',
                    'location': params.idcode.location,
                    'processInstId': params.idcode.processInstId,
                },
                'jsonName': 'appDecision',
                'appDecision': params.decisiondata
            }
        }
    )
}

/// 第一议题 提交
export function dyytSubmitProcess(params) {
    console.log('name:' + params.userName)
    var usrls = 'UsStudy$api$startSubmitProcess';
    return request(
        {
            url: process.env.VUE_APP_URL + '/action/openapi/bps/common/transmit/' + usrls + '?source=MOBILE',
            contentType: 'application/json;charset=UTF-8',
            data: {
                'currentUserCode': util.encrypt(params.userName),
                'access_token': getToken(),
                'appCode': dwdyytCode,
                'versionName': '2.7.92',
                'kv': {
                    'source': 'MOBILE',
                    'currentUserCode': util.encrypt(params.userName),
                    'workItemId': params.idcode.workItemId,
                    'outcome': params.outcome,
                    'processInstId': params.idcode.processInstId,
                    'location': params.idcode.location,
                    'outcomeName': params.outcomeName,
                },
                'jsonName': 'appDecision',
                'appDecision': params.flowParam
            }
        }
    )
}

/// 第一议题 台账列表 分公司
export function getFGSDWXXTZList(params) {
    return request(
        {
            url: process.env.VUE_APP_URL + '/action/openapi/bps/common/transmit/' +
                'UsStudy$api$selectAll',
            contentType: 'application/json;charset=UTF-8',
            data: {
                'access_token': getToken(),
                'appCode': dwdyytCode,
                'currentUserCode': util.encrypt(params.userName),
                'versionName': '2.7.92',
                'kv': {
                    'currentUserCode': util.encrypt(params.userName),
                    'source': 'MOBILE',
                    'page': params.page,
                    'rows': params.rows,
                    'size': params.size,
                },
                'jsonName': 'appDecision',
                'appDecision': {
                    'startDate': params.startTime,
                    'endDate': params.endTime,
                    'title': params.title,
                    'page': params.page,
                    'rows': params.rows
                }
            }
        }
    )
}


/// 第一议题 台账列表 省公司
export function getSGSDWXXTZList(params) {
    return request(
        {
            url: process.env.VUE_APP_URL + '/action/openapi/bps/common/transmit/' +
                'UsStudy$api$selectAllPro',
            contentType: 'application/json;charset=UTF-8',
            data: {
                'access_token': getToken(),
                'appCode': dwdyytCode,
                'currentUserCode': util.encrypt(params.userName),
                'versionName': '2.7.92',
                'kv': {
                    'currentUserCode': util.encrypt(params.userName),
                    'source': 'MOBILE',
                    'page': params.page,
                    'rows': params.rows,
                    'size': params.size,
                },
                'jsonName': 'appDecision',
                'appDecision': {
                    'startDate': params.startTime,
                    'endDate': params.endTime,
                    'title': params.title,
                    'page': params.page,
                    'rows': params.rows
                }
            }
        }
    )
}

/// 第一议题 台账 详情
export function getDYYTTZDetail(params) {
    return request(
        {
            url: process.env.VUE_APP_URL + '/action/openapi/bps/common/transmit/' +
                'UsStudy$api$findByIdPro',
            contentType: 'application/json;charset=UTF-8',
            data: {
                'access_token': getToken(),
                'appCode': dwdyytCode,
                'currentUserCode': util.encrypt(params.userName),
                'versionName': '2.7.92',
                'kv': {
                    'source': 'MOBILE',
                    'id': params.taizhangId,
                },
            }
        }
    )
}


/// 意见列表信息
export function getOpinionDetail(params) {
    return request({
        url: process.env.VUE_APP_URL + '/action/openapi/bps/common/transmit/' +
            'queryOpinionHistory$api$getWfOptMags?source=MOBILE',
        contentType: 'application/json;charset=UTF-8',
        data: {
            'access_token': getToken(),
            'appCode': dwdyytCode,
            'currentUserCode': util.encrypt(params.userName),
            'versionName': '2.7.92',
            'kv': {
                'source': 'MOBILE',
                'currentUserCode': util.encrypt(params.userName),
                'processInstId': params.processInstId,
            }
        }
    })
}

/// 当前办理人
export function getDYYTHistory(params) {
    return request(
        {
            url: process.env.VUE_APP_URL + '/action/openapi/bps/common/transmit/' +
                'queryProcessHistory$api$getWorkItems',
            contentType: 'application/json;charset=UTF-8',
            data: {
                'access_token': getToken(),
                'appCode': dwdyytCode,
                'currentUserCode': util.encrypt(params.userName),
                'versionName': '2.7.92',
                'kv': {
                    'source': 'MOBILE',
                    'processInstId': params.processInstId,
                },
            }
        }
    )
}


export function dyytUploadProcessFiles(fd, params) {
    console.log('CCCCCCCCCC' + process.env.VUE_APP_UPFILE)
    return request({
        url: process.env.VUE_APP_URL + '/action/openapi/bps/common/uploadFile?pmInsType=A&pmInsTypePart=1&appcode=zbjqdyyt&currentUserCode='
            + util.encrypt(params.userName) + '&access_token=' + getToken(),
        contentType: 'multipart/form-data',
        data: fd,
        catch: true
    })
}